// pages/index1/index.js
const config = require("../../utils/config.js")
const req = require("../../utils/request.js")
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerList:[],
    categoryListI:[],
    categoryListN: [],
    categoryListId:[]
  },
  getData: function () {
    var that=this
    var bannerList = that.data.bannerList
    req.request(config.banner, "GET", {}, function (res) {
      for(var i=0;i<res.data.data.banner.length;i++){
        bannerList[i] = res.data.data.banner[i].image_url
        that.setData({
          bannerList:bannerList
        })
      }
    })
  },
  getClassify: function () {
    var that = this
    req.request(config.catalog, "GET", {}, function (res) {
      console.log(res)
      var categoryListI = that.data.categoryListI
      var categoryListN = that.data.categoryListN
      var categoryListId = that.data.categoryListId
      for (var j = 0; j < res.data.data.categoryList.length;j++){
        categoryListI[j] = res.data.data.categoryList[j].img_url
        categoryListN[j] = res.data.data.categoryList[j].name
        categoryListId[j] = res.data.data.categoryList[j].id
      }
      that.setData({
        categoryListI: categoryListI,
        categoryListN: categoryListN,
        categoryListId: categoryListId
      })
      app.globalData.categoryListId = categoryListId
      console.log(app.globalData.categoryListId)
    })
  },
  particulars:function(res){
    console.log(res)
    app.globalData.index = res.currentTarget.dataset.index
      wx.navigateTo({
        url: '../particulars/particulars'
      })
  },
  // 跳转分类
  classify:function(){
    wx.navigateTo({
      url:"../classify/classify"
    })
  },
  // 跳转优品汇专区
  division:function(){
    wx.navigateTo({
      url: '../SuperiorZone/SuperiorZone'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
    this.getClassify()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})